<template>
  <view class="contain_sendgoods">
    <view class="cu-list menu card-menu sm-border cu-address">
      <view class="flex">
        <view class="site-left flex flex-direction">
          <view>
            <image src="@/assets/images/index/我要发货/shouye_icon_fahuo.png" style="width: 42px; height: 42px" />
          </view>
          <view class="border-dash"></view>
          <view class="margin-t80">
            <image src="@/assets/images/index/我要发货/shouye_icon_shouhuo.png" style="width: 42px; height: 42px" />
          </view>
        </view>
        <view class="site-right width100">
          <view class="flex align-center sh-solid justify-between">
            <view @click="addAddress(AddressInfoDirection.Sender)">
              <view class="sh-text-color sh-font-ls sh-line-height48 sh-bold">{{
                sendGoodsStore.sendAddressInfo ? `${sendGoodsStore.sendAddressInfo?.preName}
                              ${sendGoodsStore.sendAddressInfo?.preTel}`
                : `${sendGoodsStore.changeList.shipper} ${sendGoodsStore.changeList.shipperMobile}`
              }}</view>
              <view class="sh-write-color sh-font-sm"
                style="width:500rpx;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">{{
                  sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAddress :
                  sendGoodsStore.changeList.toFromAdd
                }}</view>
            </view>
            <view class="flex flex-direction align-center" @click="goAddressBook(AddressInfoDirection.Sender)">
              <image src="@/assets/images/index/我要发货/icon_dizhibu.png" style="width: 28px; height: 28px" />
              <text class="sh-gary-color sh-font-size">地址簿</text>
            </view>
          </view>
          <view class="flex align-center justify-between margin-t10">
            <view @click="addAddress(AddressInfoDirection.Getter)">
              <view class="sh-text-color sh-font-ls sh-line-height48 sh-bold">{{ sendGoodsStore.getAddressInfo ?
                `${sendGoodsStore.getAddressInfo?.preName} ${sendGoodsStore.getAddressInfo?.preTel}`
                : `${sendGoodsStore.changeList.receiver} ${sendGoodsStore.changeList.receiverMobile}`
              }}</view>
              <view class="sh-write-color sh-font-sm"
                style="width:500rpx;white-space:nowrap;overflow:hidden;text-overflow:ellipsis">{{
                  sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAddress : sendGoodsStore.changeList.fromAdd
                }}</view>
            </view>
            <view class="flex flex-direction align-center" @click="goAddressBook(AddressInfoDirection.Getter)">
              <image src="@/assets/images/index/我要发货/icon_dizhibu.png" style="width: 28px; height: 28px" />
              <text class="sh-gary-color sh-font-size">地址簿</text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="cu-list menu card-menu" :class="{ biaoji: goodsInfo.length != 0 }">
      <view class="cu-item arrow biaoshi">
        <view class="content sh-text-666">
          <text class="sh-text-666">货物信息</text>
        </view>
        <view class="action comGoods" v-if="goodsInfo.length == 0" @click="addGoods">
          <text class="sh-text-999">请完善货物信息</text>
        </view>
        <view class="leftButton" v-else @click="addGoods">添加货物</view>
      </view>
      <view class="goods_infos">
        <view class="goods_infos_div" v-for="(item, index) in goodsInfo" :key="index">
          <view class="text">{{ item.goodsName }}{{ item.goodsNumber }}件，{{
            item.weigh
          }}Kg，{{ item.goodsVolume }}m³，{{ item.packing }}</view>
          <view class="edit">
            <span class="b" @click="editGoods(index)">编辑</span>
            <span class="d" @click="delGoods(index)">删除</span>
          </view>
        </view>
      </view>
      <view class="cu-item" :class="{ showc: sendGoodsStore.clearingForm == '3' }">
        <view class="content">
          <text class="sh-text-666">付款方式</text>
        </view>
        <view class="action flex">
          <nut-radio-group v-model="sendGoodsStore.clearingForm" @change="doChange" direction="horizontal">
            <nut-radio label="1">现付</nut-radio>
            <nut-radio label="2">提付</nut-radio>
            <nut-radio label="3" :disabled="qdComList.length === 0">签单</nut-radio>
          </nut-radio-group>
        </view>
      </view>
      <view class="clearingform" v-if="sendGoodsStore.clearingForm == '3'">
        <view class="clearingform_div">
          <view class="box">
            <view class="box_label">签单单位</view>
            <view class="box_value">{{ sendGoodsStore.clearingFormInfo.customerName }}</view>
          </view>
          <view class="box">
            <view class="box_label">结算地</view>
            <view class="box_value">{{ sendGoodsStore.clearingFormInfo.companyName }}</view>
          </view>
          <view class="box">
            <view class="box_label">回单要求</view>
            <view class="box_value" @click="openDemandDialog">{{ sendGoodsStore.clearingFormInfo.demand.require }}＞</view>
          </view>
        </view>
      </view>

      <view class="cu-item">
        <view class="content">
          <text class="sh-text-666">接货方式</text>
        </view>
        <view class="action flex">
          <nut-radio-group v-model="sendGoodsStore.receivingStatus" @change="receivingStatusChange()"
            direction="horizontal">
            <nut-radio label="0">无需接货</nut-radio>
            <nut-radio label="1">上门接货</nut-radio>
          </nut-radio-group>
        </view>
      </view>
      <view class="h_item" v-if="sendGoodsStore.receivingStatus === '1'">
        <dataChoose :title="'接货开始时间'"></dataChoose>
        <dataChoose :title="'接货结束时间'"></dataChoose>
      </view>
      <view class="cu-item arrow" style="padding-right: 30rpx">
        <view class="content">
          <text class="sh-text-666">提货方式</text>
        </view>
        <view class="action comGoods" @click="openPickUpModePop">
          <text class="sh-text-999"
            v-if="sendGoodsStore.pickUpMode == '2' && !sendGoodsStore.deliveryTime.start">{{ deliveryTypeShow() }}</text>
          <text class="sh-text-25" v-else>{{ deliveryTypeShow() }}</text>
        </view>
      </view>
      <view class="cu-item arrow" style="padding-right: 30rpx">
        <view class="content">
          <text class="sh-text-666">承运类型</text>
        </view>
        <view class="action comGoods" @click="openSendTypePop">
          <text class="sh-text-25">{{ TransSendType()
          }}{{ sendGoodsStore.jj === "1" ? "，加急" : "" }}</text>
        </view>
      </view>
    </view>

    <view class="cu-list menu card-menu">
      <view class="cu-item arrow" @click="visibleKeepMoney = !visibleKeepMoney">
        <view class="content">
          <text class="sh-text-666">保价金额</text>
        </view>
        <view class="action">
          <text class="sh-text-999" v-if="sendGoodsStore.insuredMoney == '0' || !sendGoodsStore.insuredMoney">若货物价值≥100元,
            建议保价</text>
          <text class="sh-text-25" v-else>{{ '￥' + sendGoodsStore.insuredMoney }}</text>
        </view>
      </view>
      <view class="cu-item arrow" @click="gotoMoreServer">
        <view class="content">
          <text class="sh-text-666">更多服务</text>
        </view>
        <view class="action">
          <text class="sh-text-999" v-if="sendGoodsStore.moreChoose.length == 0">请选择更多服务</text>
          <text class="sh-text-25" v-else>{{ chooseMore() }}</text>
        </view>
      </view>
    </view>
    <nut-checkbox class="message sh-text-999" v-model="isCheck" label="复选框">我已阅读并遵守<label @click="
      visibleDeal = true;
    isCheck = !isCheck;
    " class="sh-text-blue">《盛辉契约服务条款》</label></nut-checkbox>

    <!-- 保价信息弹出层 -->
    <nut-popup position="bottom" class="keep_money" round closeable v-model:visible="visibleKeepMoney">
      <view class="goods_info">保价
        <nut-switch v-model="insuredPriceBool" active-color="#0966ff" @change="changeKeepMoneySwitch" />
      </view>
      <view class="money-height">
        <view class="keep_input">
          <view>保价金额</view><nut-input @update:model-value="insureFeeCount" :disabled="!insuredPriceBool"
            v-model="sendGoodsStore.insuredMoney" placeholder="请输入保价金额" type="number" />
          <view>元</view>
        </view>

        <!-- 保价提示 -->
        <view class="pay_Info">
          <text>温馨提示:</text>
          <text>1、请按货物实际价值来填写价值声明保价。</text>
          <text>2、保价费按货物价值的0.4%收取，最低5元每票。</text>
        </view>
        <view class="keep_money_foot">
          <view class="left">
            <view class="one">保费</view>
            <view class="tow">¥{{ sendGoodsStore.insuredFee }}</view>
          </view>
          <view class="right" @click="getKeepMoneyInfo" :class="{
            insureMoney_active:
              !insuredPriceBool || (sendGoodsStore.insuredMoney && Number(sendGoodsStore.insuredMoney) !== 0)
          }">保 价</view>
        </view>
      </view>
    </nut-popup>

    <!-- 协议 -->
    <nut-popup position="bottom" :round="true" class="getGoods" closeable style="height: 80%"
      v-model:visible="visibleDeal">
      <view class="goods_info">盛辉契约服务条约</view>
      <view class="protocol-list">
        <view class="margin-t20">
          1、托运人应如实告知承运人所托运货物的名称、性质、重量、数量、价值等必要信息，准确申报或填写、认真核对承运单信息，对承运单所填写内容之真实性负责；若托运人所提供的收货人信息等错误造成交货延迟或损失的，承运人不承担任何责任。
        </view>
        <view class="margin-t20">
          2、托运人应对所托货物按照行业标准妥善包装，使其适合运输。托运人不得托运或在所托运货物中夹带危险品、国家禁止运输的物品（包含但不仅限于假冒伪劣产品）；并不得隐瞒或夹带承运单所填报货物名称之外的物品。否则承运人有权随时随处卸货，因此发生的后果由托运人自负，并由托运人赔偿给承运人造成的一切损失。
        </view>
        <view class="margin-t20">
          3、收货人在收到提货或送货通知后最迟应在3日内提货或安排接收货物逾期应支付超出天数的仓储费和保管费，轻货按照5元/m³/天收取，重货按照15元/T/天收取，两者相比取最大值作为收费标准，最低5元每票。凡逾期超过30日，承运人有权视情对货物进行处理，由此产生的相应损失承运人不予承担赔偿责任。
        </view>
        <view class="margin-t20">
          4、托运人或收货人无故不支付费用的，承运人可以对承运货物行使留置权及其他补救性权利，由此而产生的后果由托运人或收货人承担。</view>
        <view class="margin-t20">
          5、托运人有权选择办理货物保价运输，保价费按货物价值的0.4%收取，最低5元每票。托运人选择保价运输的，货物全部灭失，按货物保价声明价值赔偿；货物部分毁损或灭失，按声明价值的损失比例赔偿；声明价值高于实际价值的，按实际价值赔偿；若货物损坏进行修复的，按实际修复费进行赔偿。托运易碎品托运人应妥善进行防护性包装，若运输途中发生破损，除能证明该破损系承运人造成包装物破坏致使托运货物损失外，承运人不承担赔偿责任
        </view>
        <view class="margin-t20">
          6、未办理保价运输而发生货物灭失或损坏的，每件货物价值在300元以内的按货物的实际损失赔偿；每件货物价值超过300元的，承运人对每件货物的最高赔偿额不超过300元。按以上方式计算得出的赔偿额超过货物实际价值的部分无效。
        </view>
        <view class="margin-t20">7、托运人委托承运人代收货款不代表该次货物的实际价值，如果承运货物出现损坏或灭失的赔偿额应按照承运单第5、6条约定赔偿，与代收货款无关。</view>
        <view class="margin-t20">8、收货人签收货物后，表明货物已完好无损交付，自签收之时起该货物的损坏、短缺、灭失、污染、变质等一切风险和责任转移至收货人处，与承运人无关。</view>
        <view class="margin-t20">9、凡因承运单或与承运单有关的争议，当事人可以通过协商或调解解决，协商或调解不成，双方同意由福州市晋安区人民法院管辖。</view>
      </view>
      <com-submit @click="submit"></com-submit>
    </nut-popup>
  </view>
  <view class="foot">
    <foot @submit="submit"></foot>
  </view>
  <!-- 提货方式弹窗 -->
  <nut-popup :close-on-click-overlay="false" :style="{ height: '904rpx' }" position="bottom" :closeable="true" round
    v-model:visible="pickUpModeShow" @click-close-icon="closePickUpModel">
    <pickUpModePop :companyList="companyList" @doSure="doSure"></pickUpModePop>
  </nut-popup>
  <!-- 承运类型弹窗 -->
  <nut-popup :style="{ height: '60%' }" position="bottom" :closeable="true" round v-model:visible="sendTypeShow">
    <sendType @closeSendTypePop="closeSendTypePop"></sendType>
  </nut-popup>
  <send-form :show="showSendForm" :type="addressSendType" :operateType="'add'" @close="closeSendForm"></send-form>
  <!--回单要求弹窗-->
  <returnDemandPop :show="showDemandDialog" :demandList="customerdemandList" @close="showDemandDialog = false">
  </returnDemandPop>
</template>

<script setup lang="ts">
import Taro, { useDidShow, useLoad } from "@tarojs/taro";
import { ref, computed } from "vue";
import useAddressInfoStore from "@/store/addressbook";
import useSendGoodsStore from "@/store/sendGoods";
import useUserInfoStore from "@/store/user";
import {
  $post,
  getAddressLists,
  $get,
  getSignUnit,
  recommandBranch,
  recommandBranchNew,
  RecommandParam,
  RecommandReturnParam,
  RecommandReturnParamNew,
  getLongPrice,
  calcCargoPrice,
  calcDeliveryPrice,
  calcDischargePrice,
  publicInfo,
  orderOrder,
  getBranchTel,
} from "@/@api";
import { AddressInfoDirection } from "@/type";
import dayjs from "dayjs";
import { AddressInfo } from "@/@api/AddressInfo";
import dataChoose from "@/pages/sendGoods/dataChoose";
import { GoodsType } from "../sendGoods/goodsType";
import pickUpModePop from "../sendGoods/pickUpModePop.vue";
import sendType from "@/pages/sendGoods/sendType";
import foot from "./foot.vue";
import returnDemandPop from '../sendGoods/returnDemandPop'

const showSendForm = ref<boolean>(false)
const addressSendType = ref<string>('1')

const insuredPriceBool = ref<boolean>(false)

export interface PointInfo {
  address: string;
  branchcompanyno: string;
  companyname: string;
  tel: string;
}

function addAddress(val) {
  addressSendType.value = val
  showSendForm.value = true
}
function closeSendForm(refresh: boolean) {
  showSendForm.value = false
  if (refresh) {

  }
}

function chooseMore() {
  // if(sendGoodsStore.moreChoose.indexOf('1'))
  if (sendGoodsStore.moreChoose.length == 3) {
    return "代收货款,单据服务,包装服务";
  } else if (sendGoodsStore.moreChoose.length == 2) {
    if (
      sendGoodsStore.moreChoose.indexOf("1") != -1 &&
      sendGoodsStore.moreChoose.indexOf("2") != -1
    ) {
      return "代收货款,单据服务";
    } else if (
      sendGoodsStore.moreChoose.indexOf("1") != -1 &&
      sendGoodsStore.moreChoose.indexOf("3") != -1
    ) {
      return "代收货款,包装服务";
    } else if (
      sendGoodsStore.moreChoose.indexOf("2") != -1 &&
      sendGoodsStore.moreChoose.indexOf("3") != -1
    ) {
      return "单据服务,包装服务";
    }
  } else {
    if (sendGoodsStore.moreChoose.indexOf("1") != -1) {
      return "代收货款";
    } else if (sendGoodsStore.moreChoose.indexOf("2") != -1) {
      return "单据服务";
    } else if (sendGoodsStore.moreChoose.indexOf("3") != -1) {
      return "包装服务";
    }
  }
}
//费用
//长途运费
async function longPriceCount() {
  console.log('计算单价哦');
  if (sendGoodsStore.sendBranch.pending || sendGoodsStore.getBranch.pending) {
    return;
  }
  if (!sendGoodsStore.goodsVolume || !sendGoodsStore.weigh) {
    return;
  }

  let res = await getLongPrice({
    strarea:
      sendGoodsStore.sendBranch.info.PROVINCE +
      " " +
      sendGoodsStore.sendBranch.info.CITY +
      " " +
      sendGoodsStore.sendBranch.info.AREA,
    desarea:
      sendGoodsStore.getBranch.info.PROVINCE +
      " " +
      sendGoodsStore.getBranch.info.CITY +
      " " +
      sendGoodsStore.getBranch.info.AREA,
    startCompany: sendGoodsStore.sendBranch.info.branchno,
    descCompany: sendGoodsStore.getBranch.info.branchno,
    type: TransSendType(),
    senddate: dayjs().format("YYYY-MM-DD"),
    volume: sendGoodsStore.goodsVolume,
    weight: sendGoodsStore.weigh,
  });
  console.log(res);
  res = JSON.parse(res);
  //是否有配置
  if (res.result === "True") {
    sendGoodsStore.costList[3].m = String(res.price);
  } else {
    sendGoodsStore.costList[3].m = "0";
  }
  console.log(sendGoodsStore.costList[3].m, "ww");
}
//接货费
async function calcCargoPriceCount() {
  if (sendGoodsStore.sendBranch.pending) {
    return;
  }
  if (!sendGoodsStore.goodsVolume || !sendGoodsStore.weigh) {

    return;
  }

  if (sendGoodsStore.receivingStatus == "0") {
    return;
  }
  let branchAddress = await getAddressByLngLat(sendGoodsStore.getBranch.info.lng, sendGoodsStore.getBranch.info.lat)
  let res = await calcCargoPrice({
    orderId: null,
    //mileage: distance / 1000,
    branch: sendGoodsStore.sendBranch.info.branchno,
    weight: sendGoodsStore.weigh,
    volume: sendGoodsStore.goodsVolume,
    source: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAddress : sendGoodsStore.changeList.fromAdd,
    destination: branchAddress,
    excess: false, //是否续重
    first: true,
  });
  console.log(res, "接货费");
  sendGoodsStore.costList[2].m = String(res);
}
//送货费
async function calcDeliveryPriceCount() {
  if (sendGoodsStore.getBranch.pending) {
    return;
  }
  if (!sendGoodsStore.goodsVolume || !sendGoodsStore.weigh) {
    return;
  }
  if (sendGoodsStore.pickUpMode != "2") {
    return;
  }
  if (
    sendGoodsStore.pickUpMode == "2" &&
    sendGoodsStore.deliveryTime.start == ""
  ) {
    return;
  }
  let distance = await getDesDistance('2')
  let res = await calcDeliveryPrice({
    mileage: distance / 1000,
    branch: sendGoodsStore.getBranch.info.branchno, //自助机编号
    djhw: false, //是否大件货物
    weight: sendGoodsStore.weigh,
    volume: sendGoodsStore.goodsVolume,
    jj: sendGoodsStore.jj == "0" ? false : true, //是否加急
    xss: false, //是否限时送
    special: false, //是否特派区域
    scs: sendGoodsStore.deliveryType == "1" ? true : false,
    jc: sendGoodsStore.deliveryType == "2" ? true : false,
    bg: sendGoodsStore.deliveryType == "3" ? true : false,
    numbers: 1,
    sendTypeSep: sendGoodsStore.sendType == "1" ? true : false, //是否快件
    excess: false, //是否续重
    first: true,
  });
  console.log(res);
  sendGoodsStore.costList[1].m = String(res);
}
//卸货费
async function calcDischargePriceCount() {
  if (!sendGoodsStore.goodsVolume || !sendGoodsStore.weigh) {
    return;
  }
  if (sendGoodsStore.dischargeCargo == "0") {
    return;
  }

  let res = await calcDischargePrice({
    weight: sendGoodsStore.weigh,
    volume: sendGoodsStore.goodsVolume,
    cargoType: sendGoodsStore.dischargeServer,
    isUpStairs: Number(sendGoodsStore.elevatorNum) < 1 ? false : true,
    isElevator: sendGoodsStore.dischargeElevator == "1" ? true : false,
    floor: sendGoodsStore.elevatorNum,
  });
  console.log(sendGoodsStore.elevatorNum);
  console.log(res, "卸货");
  sendGoodsStore.costList[7].m = String(res);
}
function transCargoType() {
  if (sendGoodsStore.dischargeServer == "1") {
    return "0";
  } else if (sendGoodsStore.dischargeServer == "2") {
    return "1";
  } else {
    return "2";
  }
}
function doSure(e: string) {
  pickUpModeShow.value = false;
  //sendGoodsStore.getBranch.info = companyList.value[branchIndex]
  console.log(e, sendGoodsStore.pickUpMode, '打印一下');
  //自提
  if (sendGoodsStore.pickUpMode === "1") {
    sendGoodsStore.costList[1].m = '0'
    sendGoodsStore.costList[7].m = '0'
    return
  }
  //配送
  if (sendGoodsStore.pickUpMode === "2") {
    calcDeliveryPriceCount();
    calcDischargePriceCount();
    return
  }
  //直送
  if (sendGoodsStore.pickUpMode === "3") {
    sendGoodsStore.costList[1].m = '0'
    calcDischargePriceCount();
    return
  }
}
function closeSendTypePop(e: string) {
  sendTypeShow.value = false;
  console.log(e);
  longPriceCount();
  calcDeliveryPriceCount();
}

//提货弹窗关闭
function closePickUpModel() {
  // sendGoodsStore.pickUpMode = "2";
  // sendGoodsStore.deliveryTime = {
  //   start: "",
  //   end: "",
  // };
  // sendGoodsStore.dischargeCargo = "0";
}
//页面上的提货方式回显
function deliveryTypeShow() {
  if (
    sendGoodsStore.pickUpMode == "2" &&
    sendGoodsStore.deliveryTime.start == ""
  ) {
    return "请选择提货方式";
  }
  if (sendGoodsStore.dischargeCargo == "0") {
    if (sendGoodsStore.pickUpMode == "1") {
      return "自提，" + sendGoodsStore.getBranch.info.COMPANYNAME;
    } else if (sendGoodsStore.pickUpMode == "2") {
      return "配送，" + sendGoodsStore.getBranch.info.COMPANYNAME;
    } else {
      return "直送";
    }
  } else {
    if (sendGoodsStore.pickUpMode == "1") {
      return "自提,卸货服务";
    } else if (sendGoodsStore.pickUpMode == "2") {
      return "配送,卸货服务";
    } else {
      return "直送,卸货服务";
    }
  }
}

//承运类型弹框
const sendTypeShow = ref<boolean>(false);
function openSendTypePop() {
  sendTypeShow.value = true;
}

const store = useAddressInfoStore();
const sendGoodsStore = useSendGoodsStore();
const userStore = useUserInfoStore();

const visibleKeepMoney = ref(false); //保价
const visibleDeal = ref(false);

const isCheck = ref(false);
const visibleGetGoods = ref(false);
const showBasic = ref(false); //物品详情

const agentChecked = ref<boolean>(false); // 代收开关
const signChecked = ref<boolean>(false); // 签收开关

const nowIndex = ref(0);

const popularPoint = ref<PointInfo[]>([]);
const allPoint = ref<PointInfo[]>([]);

const qdComList = ref<any[]>([]); //签单单位
const customerdemandList = ref<any[]>([]); //回单要求
const showDemandDialog = ref<boolean>(false);//回单要求选择弹窗

const selectNetPoint = ref<PointInfo>({
  address: "",
  branchcompanyno: "",
  companyname: "",
  tel: "",
});
const myKeepMoney = ref("");

const myInfo = ref({
  cargoname: "",
  package: "",
  weight: "",
  volume: "",
  quantity: "",
});
//去更多服务页面
function gotoMoreServer() {
  Taro.navigateTo({
    url: "/pages/sendGoods/moreServer",
  });
}
// 货物信息大表单
const goodsInfo = ref<GoodsType[]>(sendGoodsStore.goodsInfo);
// 全部信息
//添加货物
function addGoods() {
  sendGoodsStore.goodsAddOrEditIndex = null;
  Taro.navigateTo({
    url: "/pages/sendGoods/goods",
  });
}
//编辑货物
function editGoods(index: number) {
  console.log(goodsInfo.value, '点击编辑');
  sendGoodsStore.goodsAddOrEditIndex = index;
  Taro.navigateTo({
    url: "/pages/sendGoods/goods",
  });
}
//删除货物
function delGoods(index: number) {
  goodsInfo.value.splice(index, 1);
  sendGoodsStore.goodsInfo = goodsInfo.value;
  console.log(sendGoodsStore.goodsInfo, goodsInfo.value, '修改后');
  if (goodsInfo.value.length == 0) {
    sendGoodsStore.goodsNumber = 0;
    sendGoodsStore.goodsVolume = 0;
    sendGoodsStore.weigh = 0;
    sendGoodsStore.costList[3].m = "0"
  }
  else {
    let vo = 0;
    let w = 0;
    let n = 0;
    sendGoodsStore.goodsInfo.forEach((it) => {
      vo = vo + Number(it.goodsVolume);
      w = w + Number(it.weigh);
      n = n + Number(it.goodsNumber);
    });
    sendGoodsStore.goodsNumber = n;
    sendGoodsStore.goodsVolume = vo;
    sendGoodsStore.weigh = w;
  }
  longPriceCount();
  calcCargoPriceCount();
  calcDeliveryPriceCount();
  calcDischargePriceCount();
}
//承运类型分类
function TransSendType() {
  if (sendGoodsStore.sendType == "1") {
    return "快件";
  } else if (sendGoodsStore.sendType == "2") {
    return "普件";
  } else if (sendGoodsStore.sendType == "3") {
    return "整车";
  } else if (sendGoodsStore.sendType == "4") {
    return "560经济件";
  } else if (sendGoodsStore.sendType == "5") {
    return "560商务件";
  } else if (sendGoodsStore.sendType == "6") {
    return "次日达";
  } else {
    return "隔日达";
  }
}
////自提的网点列表
const companyList = ref<RecommandReturnParamNew[]>([]);
// 进入触发事件
useLoad(async () => {
  console.log('load触发');
  goodsInfo.value = sendGoodsStore.goodsInfo.map((item) => {
    if (typeof (item.specifications) === 'string') {
      let specifications = item.specifications.split(';')
      specifications = specifications.slice(0, specifications.legnth - 1).map(s => {
        let strArr = s.split('cm*')
        return {
          l: strArr[0],
          w: strArr[0],
          h: strArr[0],
          sum: strArr[0],
        }
      })
      return {
        ...item,
        specifications: specifications
      }
    }
    else {
      return {
        ...item
      }
    }

  })
  //地址簿 默认处理
  //   if (!sendGoodsStore.sendAddressInfo) {
  //     const res1 = await $get<any>("/selfmachine-system/workerAddress/list/1", {
  //       customerCode: userStore.userInfo.customerCode,
  //     });
  //     sendGoodsStore.sendAddressInfo = res1.data.data.find(
  //       (item: AddressInfo) => {
  //         return item.isDefault === "1";
  //       }
  //     );
  //   }

  //   if (!sendGoodsStore.getAddressInfo) {
  //     const res2 = await $get<any>("/selfmachine-system/workerAddress/list/2", {
  //       customerCode: userStore.userInfo.customerCode,
  //     });
  //     sendGoodsStore.getAddressInfo = res2.data.data.find((item: AddressInfo) => {
  //       return item.isDefault === "2";
  //     });
  //   }

  //配送时间处理
  if (sendGoodsStore.pickUpMode == '2') {
    //sendGoodsStore.deliveryTime
  }

  //网点处理
  companyList.value = await reqGetBranch({
    carriageType: '1',
    ISShipForMe: '0',
    did: '',
    address: sendGoodsStore.changeList.fromAdd,
  });
  sendGoodsStore.getBranch.info = companyList.value.find((item) => {
    return item.branchno === sendGoodsStore.changeList.destinationBranch
  });
  sendGoodsStore.getBranch.pending = false;

  let res3 = await reqGetBranch({
    carriageType: '0',
    ISShipForMe: '0',
    did: '',
    address: sendGoodsStore.changeList.toFromAdd,
  });
  sendGoodsStore.sendBranch.info = res3.find((item) => {
    return item.branchno === sendGoodsStore.changeList.startBranch
  });
  console.log(sendGoodsStore.sendBranch.info, sendGoodsStore.changeList.startBranch, 'sendGoodsStore.sendBranch.info');
  sendGoodsStore.sendBranch.pending = false;

  //签单单位

  try {
    let qdCom = await getSignUnit({
      customerCode: userStore.userInfo.customerCode,
    })
    qdComList.value = qdCom || []
    customerdemandList.value = qdComList.value[0]?.customerdemandList || []
    console.log(customerdemandList.value, 'customerdemandList.value')
    sendGoodsStore.billServer = sendGoodsStore.billServer || ''
    if (sendGoodsStore.clearingForm == '3' && qdComList.value.length) {
      sendGoodsStore.costList[0].m = '0'
      sendGoodsStore.costList[6].m = '0'
      sendGoodsStore.clearingFormInfo.contractedNo = qdCom[0].contractedNo
      sendGoodsStore.clearingFormInfo.companyName = qdCom[0].companyName
      sendGoodsStore.clearingFormInfo.customerName = qdCom[0].customerName
      sendGoodsStore.clearingFormInfo.demand = {}
      if (sendGoodsStore.moreChoose.indexOf('2') === -1) {
        sendGoodsStore.moreChoose.push('2')
      }
      //根据billserver判断回显
      customerdemandList.value.forEach((item) => {
        if (item.require === '签回承运单' || item.require === '承运单') {
          sendGoodsStore.clearingFormInfo.demand = item
        }
      })
      if (sendGoodsStore.billServer.indexOf('2') !== -1) {
        sendGoodsStore.billServer = '2'
        sendGoodsStore.costList[6].m = '0'
        customerdemandList.value.forEach((item) => {
          if (item.require === '签回承运单' || item.require === '承运单') {
            sendGoodsStore.clearingFormInfo.demand = item
          }
        })
      }
      else {
        sendGoodsStore.billServer = '3'
        sendGoodsStore.costList[6].m = '0'
        customerdemandList.value.forEach((item) => {
          if (item.require !== '签回承运单' && item.require !== '承运单') {
            sendGoodsStore.clearingFormInfo.demand = item
          }
        })
      }
    }
    else {
      sendGoodsStore.costList[0].m = '2'
      if (sendGoodsStore.billServer.indexOf('2') !== -1) {
        sendGoodsStore.billServer = '2'
        sendGoodsStore.costList[6].m = '5'
      }
      else {
        sendGoodsStore.billServer = '3'
        sendGoodsStore.costList[6].m = '10'
        customerdemandList.value.forEach((item) => {
          if (item.require !== '签回承运单' && item.require !== '承运单') {
            sendGoodsStore.clearingFormInfo.demand = item
          }
        })
      }
    }
  }
  catch (error) {
    console.log(error, "我错啦");
  }
  //保价开关切换
  insuredPriceBool.value = !(!sendGoodsStore.insuredPrice || Number(sendGoodsStore.insuredMoney) == 0)
  getKeepMoneyInfo();
  //更多服务
  sendGoodsStore.moreChoose = []
  if (sendGoodsStore.serveFee && sendGoodsStore.serveFee !== '0') {
    sendGoodsStore.moreChoose.push('1')
    sendGoodsStore.costList[4].m = sendGoodsStore.serveFee || '0'
  }
  if (sendGoodsStore.packing == '1') {
    sendGoodsStore.moreChoose.push('3')
  }
  if (sendGoodsStore.billServer) {
    sendGoodsStore.moreChoose.push('2')
  }
  longPriceCount();
  calcCargoPriceCount();
  calcDeliveryPriceCount();
  calcDischargePriceCount();
});
useDidShow(async () => {
  let pages = Taro.getCurrentPages();
  let currPage = pages[pages.length - 1]
  if (currPage.__data__.changeGoods) {
    goodsInfo.value = sendGoodsStore.goodsInfo
    longPriceCount();
    calcCargoPriceCount();
    calcDeliveryPriceCount();
    calcDischargePriceCount();
  }
  if (currPage.__data__.chooseAddress) {
    if (sendGoodsStore.getAddressInfo) {
      companyList.value = await reqGetBranch({
        carriageType: '1',
        ISShipForMe: '0',
        did: '',
        address: sendGoodsStore.getAddressInfo.preAddress,
      });
      sendGoodsStore.getBranch.info = companyList.value[0];
      sendGoodsStore.getBranch.pending = false;
    }
    if (sendGoodsStore.sendAddressInfo) {
      let res3 = await reqGetBranch({
        carriageType: '0',
        ISShipForMe: '0',
        did: '',
        address: sendGoodsStore.sendAddressInfo.preAddress,
      });
      sendGoodsStore.sendBranch.info = res3[0];
      sendGoodsStore.sendBranch.pending = false;
    }
  }
})
//调用推荐网点接口
async function reqGetBranch(
  item: any
): Promise<any[]> {
  let res = await recommandBranchNew(item);
  return res;
}
//提货方式开关
const pickUpModeShow = ref<boolean>(false);
function openPickUpModePop() {
  pickUpModeShow.value = true;
}
// 去地址簿
function goAddressBook(val: AddressInfoDirection) {
  (store.addressEditParameter.addressDirection = val),
    Taro.navigateTo({
      url: "/pages/addressBook/index?type="+ val,
    });
}

// 去地址编辑页
function goEditAddressBook(val: AddressInfoDirection) {
  let editAddressInfo: AddressInfo | null;
  let onEditComplete: (address: AddressInfo) => void;
  if (val == AddressInfoDirection.Sender) {
    editAddressInfo = sendGoodsStore.sendAddressInfo;
    onEditComplete = (addr) => {
      sendGoodsStore.sendAddressInfo = addr;
    };
  } else {
    editAddressInfo = sendGoodsStore.getAddressInfo;
    onEditComplete = (addr) => {
      sendGoodsStore.getAddressInfo = addr;
    };
  }
  store.addressEditParameter = {
    addressInfo: editAddressInfo,
    addressDirection: val,
    onEditComplete: onEditComplete,
  };

  Taro.navigateTo({
    url: "/pages/addressBook/editAddress",
  });
}
//接货方式改变
function receivingStatusChange() {
  if (sendGoodsStore.receivingStatus == "1") {
    calcCargoPriceCount();
  }
  else {
    sendGoodsStore.costList[2].m = '0'
  }
}
// 付款方式类型改变
async function doChange() {
  if (sendGoodsStore.clearingForm == '3') {
    sendGoodsStore.costList[0].m = '0' //工本费
    sendGoodsStore.costList[6].m = '0' //单据费
    sendGoodsStore.clearingFormInfo.contractedNo = qdComList.value[0].contractedNo
    sendGoodsStore.clearingFormInfo.companyName = qdComList.value[0].companyName
    sendGoodsStore.clearingFormInfo.customerName = qdComList.value[0].customerName
    sendGoodsStore.clearingFormInfo.demand = customerdemandList.value[0]
    if (sendGoodsStore.moreChoose.indexOf('2') === -1) {
      sendGoodsStore.moreChoose.push('2')
    }
    if (sendGoodsStore.clearingFormInfo.demand.require === '签回承运单' || sendGoodsStore.clearingFormInfo.demand.require === '承运单') {
      sendGoodsStore.billServer = '2'
      sendGoodsStore.billNum = ''
    }
    else {
      sendGoodsStore.billServer = '3'
      sendGoodsStore.billNum = sendGoodsStore.clearingFormInfo.demand.require
      sendGoodsStore.costList[6].m = '10'
    }
  }
  else {
    sendGoodsStore.clearingFormInfo.contractedNo = ''
    sendGoodsStore.clearingFormInfo.companyName = ''
    sendGoodsStore.clearingFormInfo.customerName = ''
    sendGoodsStore.clearingFormInfo.demand = {}
    sendGoodsStore.billNum = ''
    sendGoodsStore.costList[0].m = '2' //工本费
    //sendGoodsStore.costList[6].m = '0' //单据费
  }
}
// 选择回单要求
const openDemandDialog = () => {
  showDemandDialog.value = true
}
// 签收单改变
function doReceiptChange(val: string) {
  sendGoodsStore.receiptBill = val;
  if (val === "0") {
    sendGoodsStore.hasletter = "False";
    sendGoodsStore.backreceipttype = "False";
  } else if (val === "1") {
    sendGoodsStore.hasletter = "True";
    sendGoodsStore.backreceipttype = "False";
  } else if (val === "2") {
    sendGoodsStore.hasletter = "False";
    sendGoodsStore.backreceipttype = "True";
  }
}
//修改保价开关
const changeKeepMoneySwitch = () => {
  if (!insuredPriceBool.value) {
    sendGoodsStore.insuredMoney = '0'
  }
}
// 获取保价信息
function getKeepMoneyInfo() {
  if (Number(sendGoodsStore.insuredMoney) === 0 || !sendGoodsStore.insuredMoney) {
    sendGoodsStore.insuredFee = 0;
    sendGoodsStore.costList[5].m = '0';
  }
  sendGoodsStore.costList[5].m = sendGoodsStore.insuredFee;
  visibleKeepMoney.value = false;
}
// 保价费计算
function insureFeeCount() {
  if (sendGoodsStore.insuredMoney == "" || sendGoodsStore.insuredMoney == "0") {
    sendGoodsStore.insuredMoney = "0";
    sendGoodsStore.insuredFee = "0";
    return;
  }
  let all = (Number(sendGoodsStore.insuredMoney) / 1000) * 4;
  all = Number(all.toFixed(2));
  if (all < 5) {
    sendGoodsStore.insuredFee = "5.00";
  } else {
    sendGoodsStore.insuredFee = String(all);
  }
}

// 选择网点
function selectPoint(index: number) {
  nowIndex.value = index;
}
function doSelect() {
  selectNetPoint.value = allPoint.value[nowIndex.value];
  visibleGetGoods.value = false;
}
// 提交
async function submit() {
  if (!isCheck.value) {
    return Taro.showToast({
      icon: "none",
      title: "请先勾选协议",
    });
  }
  //   if (!sendGoodsStore.getAddressInfo) {
  //     return Taro.showToast({
  //       icon: "none",
  //       title: "请先选择收货人",
  //     });
  //   }
  //   if (!sendGoodsStore.sendAddressInfo) {
  //     return Taro.showToast({
  //       icon: "none",
  //       title: "请先选择发货人",
  //     });
  //   }
  if (sendGoodsStore.goodsInfo.length == 0) {
    return Taro.showToast({
      icon: "none",
      title: "请添加货物",
    });
  }
  if (
    sendGoodsStore.receivingStatus == "1" &&
    (sendGoodsStore.receivingTime.start == "" || sendGoodsStore.receivingTime.end == "")
  ) {
    return Taro.showToast({
      icon: "none",
      title: "请选择接货时间段",
    });
  }
  if (sendGoodsStore.pickUpMode == '2') {
    if (!sendGoodsStore.deliveryTime.start) {
      return Taro.showToast({
        icon: "none",
        title: "请选择配送开始时间",
      })
    }
    if (!sendGoodsStore.deliveryTime.end) {
      return Taro.showToast({
        icon: "none",
        title: "请选择配送结束时间",
      })
    }
    if (sendGoodsStore.deliveryTime.start > sendGoodsStore.deliveryTime.end) {
      return Taro.showToast({
        icon: "none",
        title: "配送开始时间不能大于结束时间",
      })
    }
  }
  //货物信息
  let goodsInfo: any = sendGoodsStore.goodsInfo || [];
  goodsInfo.forEach((i, index) => {
    if (i.specifications instanceof Array) {
      let a = "";
      i.specifications.forEach((j) => {
        a = a + j.l + "cm*" + j.w + "cm*" + j.h + "cm*" + j.sum + ";";
        goodsInfo[index].specifications = a;
      });
    }
  });
  //费用信息
  let res = await publicInfo({});
  let costList: any = [];

  res.forEach((i) => {
    sendGoodsStore.costList.forEach((j) => {
      if (i.ssopRemark == j.name && j.m != "0") {
        costList.push({
          billNo: null,
          costType: i.ssopId,
          money: Number(j.m), //总费用
          actualMoney: Number(j.m), //总费用
          paid: "0", //暂时写死
          payType: "1", //暂时写死
        });
      }
    });
  });
  console.log(costList, "下单的费用查询");
  //回单类型
  let bill: any = null;
  if (sendGoodsStore.billServer.i && sendGoodsStore.billServer.j) {
    bill = sendGoodsStore.billServer.i + ";" + sendGoodsStore.billServer.j;
  } else if (sendGoodsStore.billServer.i && !sendGoodsStore.billServer.j) {
    bill = String(sendGoodsStore.billServer.i);
  } else if (!sendGoodsStore.billServer.i && sendGoodsStore.billServer.j) {
    bill = String(sendGoodsStore.billServer.j);
  }


  //是否包装
  if (sendGoodsStore.moreChoose.indexOf("3") != -1) {
    sendGoodsStore.packing = '1'
  }
  else {
    sendGoodsStore.packing = '0'
  }

  const params = {
    order: {
      filePic: "sample",
      goodsType: sendGoodsStore.dischargeServer,
      shipper: sendGoodsStore.sendAddressInfo
        ? sendGoodsStore.sendAddressInfo.preName
        : sendGoodsStore.changeList.shipper,
      shipperMobile: sendGoodsStore.sendAddressInfo
        ? sendGoodsStore.sendAddressInfo.preTel
        : sendGoodsStore.changeList.shipperMobile,
      billCompany: sendGoodsStore.clearingFormInfo.contractedNo,
      clearingForm: sendGoodsStore.clearingForm,
      receivingTime:
        sendGoodsStore.receivingStatus == "0"
          ? null
          : sendGoodsStore.receivingTime.start +
          "&&" +
          sendGoodsStore.receivingTime.end,
      isReceiving: sendGoodsStore.receivingStatus,
      receiver: sendGoodsStore.getAddressInfo
        ? sendGoodsStore.getAddressInfo.preName
        : sendGoodsStore.changeList.receiver,
      receiverMobile: sendGoodsStore.getAddressInfo
        ? sendGoodsStore.getAddressInfo.preTel
        : sendGoodsStore.changeList.receiverMobile,
      pickUpMode: sendGoodsStore.pickUpMode,
      fromAdd: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAddress : sendGoodsStore.changeList.fromAdd,
      receiverAdd: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAddress : sendGoodsStore.changeList.fromAdd,
      fromProvince: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAdd.split("/")[0] : sendGoodsStore.changeList.toProvince,
      fromCity: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAdd.split("/")[1] : sendGoodsStore.changeList.toFromCity,
      fromArea: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAdd.split("/")[2] : sendGoodsStore.changeList.toFromArea,
      fromLongitude: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.longitude : sendGoodsStore.changeList.longitude,
      fromLatitude: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.latitude : sendGoodsStore.changeList.latitude,
      toFromAdd: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAddress : sendGoodsStore.changeList.toFromAdd,
      shipperAdd: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAddress : sendGoodsStore.changeList.toFromAdd,
      toProvince: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAdd.split("/")[0] : sendGoodsStore.changeList.fromProvince,
      toFromCity: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAdd.split("/")[1] : sendGoodsStore.changeList.fromCity,
      toFromArea: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAdd.split("/")[2] : sendGoodsStore.changeList.fromArea,
      toLongitude: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.longitude : sendGoodsStore.changeList.fromLongitude,
      toLatitude: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.latitude : sendGoodsStore.changeList.fromLatitude,

      deliveryTime:
        sendGoodsStore.pickUpMode == "2"
          ? sendGoodsStore.deliveryTime.start
            ? sendGoodsStore.deliveryTime.start +
            "&&" +
            sendGoodsStore.deliveryTime.end
            : null
          : null,
      deliveryType: sendGoodsStore.deliveryType,
      sendType: sendGoodsStore.sendType, //承运类型
      urgent: sendGoodsStore.jj, //是否加急
      //isPacking: sendGoodsStore.packing, //是否包装
      packing: sendGoodsStore.packing, //是否包装
      dischargeCargo: sendGoodsStore.dischargeCargo, //是否卸货
      dischargeElevator: sendGoodsStore.dischargeElevator, // 是否楼梯
      elevatorNum: sendGoodsStore.elevatorNum, //几层
      //insuredPrice: sendGoodsStore.insuredFee == "0" ? "0" : "1", //是否保价
      insuredPrice: insuredPriceBool.value ? '1' : '0', //是否保价
      insuredMoney: sendGoodsStore.insuredMoney, //保价金额
      insuredFee: sendGoodsStore.insuredFee, //保费
      billServer: bill ? bill : sendGoodsStore.changeList.billServer, //单据服务
      collectionPayment: sendGoodsStore.moreChoose.indexOf('1') === -1 ? "0" : "1", //是否代收货款
      collectionMoney: sendGoodsStore.collectionMoney, //代收金额
      returnCycle:
        sendGoodsStore.serveFee == "0" ? null : sendGoodsStore.returnCycle, //返还周期
      serveFee: sendGoodsStore.serveFee, // 服务费
      returnType:
        sendGoodsStore.serveFee == "0" ? null : sendGoodsStore.returnType, //返还方式
      returunAccount:
        sendGoodsStore.returnType == "2" ? sendGoodsStore.returunAccount : null, //银行卡账号
      billNum: sendGoodsStore.billNum, //签几联
      startBranch: sendGoodsStore.sendBranch.info.branchno
        ? sendGoodsStore.sendBranch.info.branchno
        : sendGoodsStore.changeList.startBranch, //自助机网点编号
      destinationBranch: sendGoodsStore.getBranch.info.branchno, //收货人地址最近网点编号
    },
    goodsInfo: goodsInfo,
    costList: costList,
  };
  let oldParm = {
    filePic: sendGoodsStore.changeList.filePic,
    goodsType: sendGoodsStore.changeList.dischargeServer,
    shipper: sendGoodsStore.changeList.shipper,
    shipperMobile: sendGoodsStore.changeList.shipperMobile,
    billCompany: sendGoodsStore.changeList.billCompany,
    clearingForm:
      sendGoodsStore.changeList.clearingForm == "签单"
        ? "3"
        : sendGoodsStore.changeList.clearingForm == "提付"
          ? "2"
          : "1",
    receivingTime: sendGoodsStore.changeList.receivingTime,
    toFromAdd: sendGoodsStore.changeList.toFromAdd,
    toProvince: sendGoodsStore.changeList.toProvince,
    toFromCity: sendGoodsStore.changeList.toFromCity,
    toFromArea: sendGoodsStore.changeList.toFromArea,
    fromLongitude: sendGoodsStore.changeList.fromLongitude, //终点
    fromLatitude: sendGoodsStore.changeList.fromLatitude,
    toLongitude: sendGoodsStore.changeList.toLongitude,
    toLatitude: sendGoodsStore.changeList.toLatitude,
    isReceiving: sendGoodsStore.changeList.isReceiving,
    receiver: sendGoodsStore.changeList.receiver,
    receiverMobile: sendGoodsStore.changeList.receiverMobile,
    pickUpMode:
      sendGoodsStore.changeList.pickUpMode == "自提"
        ? "1"
        : sendGoodsStore.changeList.pickUpMode == "送货"
          ? "2"
          : "3",
    fromAdd: sendGoodsStore.changeList.fromAdd,
    fromProvince: sendGoodsStore.changeList.fromProvince,
    fromCity: sendGoodsStore.changeList.fromCity,
    fromArea: sendGoodsStore.changeList.fromArea,


    // destinationBranch: this.orderData.get.wd,
    deliveryTime: sendGoodsStore.changeList.deliveryTime,
    deliveryType: sendGoodsStore.changeList.deliveryType,
    sendType: sendGoodsStore.changeList.sendType, //承运类型
    urgent: sendGoodsStore.changeList.urgent == "false" ? "0" : "1", //是否加急
    isPacking: sendGoodsStore.changeList.isPacking, //是否包装
    packing: sendGoodsStore.packing, //是否包装
    dischargeCargo: sendGoodsStore.changeList.dischargeCargo, //是否卸货
    dischargeElevator: sendGoodsStore.changeList.dischargeElevator
      ? sendGoodsStore.changeList.dischargeElevator
      : "0", // 是否楼梯
    elevatorNum: sendGoodsStore.changeList.elevatorNum, //几层
    insuredPrice: sendGoodsStore.changeList.insuredPrice, //是否保价
    insuredMoney: sendGoodsStore.changeList.insuredMoney, //保价金额
    insuredFee: sendGoodsStore.changeList.insuredFee, //保费
    billServer: sendGoodsStore.changeList.billServer, //单据服务
    collectionPayment: sendGoodsStore.changeList.collectionPayment, //是否代收货款
    collectionMoney: sendGoodsStore.changeList.collectionMoney, //代收金额
    returnCycle:
      sendGoodsStore.changeList.serveFee == "0"
        ? null
        : sendGoodsStore.changeList.returnCycle, //返还周期
    serveFee: sendGoodsStore.changeList.serveFee, // 服务费
    returnType:
      sendGoodsStore.changeList.serveFee == "0"
        ? null
        : sendGoodsStore.changeList.returnType, //返还方式
    returunAccount: sendGoodsStore.changeList.returunAccount, //签几联
    startBranch: sendGoodsStore.changeList.startBranch, //自助机网点编号
    destinationBranch: sendGoodsStore.changeList.destinationBranch, //收货人地址最近网点编号
  };
  let postData = {
    goodsInfo: goodsInfo,
    costList: costList,
    order: {
      ...oldParm,
      ...params,
      ssoId: sendGoodsStore.changeList.ssoId.toString()
    },
    terminal: '9',
  }
  let ssEditOrder = {
    backBankAccount: null,
    backType: null,
    customerCode: userStore.userInfo.customerCode,
    haveFee: 1,
    isApplyAgain: true,
    op: "null",
    opBranch: params.order.startBranch
      ? params.order.startBranch
      : oldParm.startBranch,
    orderId: sendGoodsStore.changeList.ssoId,
    payStatus: 3,
  };
  let deff: any = [];
  for (let key in oldParm) {
    if (oldParm[key] !== params.order[key]) {
      deff.push({
        deliveryLng: params.order.fromLongitude,
        deliveryLat: params.order.fromLatitude,
        deliveryMiles: 0,
        modifyItem: key,
        modifyValue: params.order[key],
        originalValue: oldParm[key],
      });
    }
  }
  console.log(deff, "deff");///selfmachine-system/editOrder/addEditOrder
  /*
  * ssEditOrder,
    ssEditOrderDetails: deff,
  * */
  $post("/selfmachine-system/order/order", postData).then((resData: any) => {
    if (resData.data.code == 200) {
      let history_goodsName = Taro.getStorageSync('historyGoodsName') ? Taro.getStorageSync('historyGoodsName').split(',') : []
      let history_goodsType = Taro.getStorageSync('historyGoodsType') ? Taro.getStorageSync('historyGoodsType').split(',') : []
      let history_goodsPacking = Taro.getStorageSync('historyGoodsPacking') ? Taro.getStorageSync('historyGoodsPacking').split(',') : []
      sendGoodsStore.goodsInfo.forEach(item => {
        history_goodsName.unshift(item.goodsName)
        history_goodsType.unshift(item.goodsType)
        history_goodsPacking.unshift(item.packing)
      })
      Taro.setStorageSync('historyGoodsName', Array.from(new Set(history_goodsName)).slice(0, 10).join(','))
      Taro.setStorageSync('historyGoodsType', Array.from(new Set(history_goodsType)).slice(0, 10).join(','))
      Taro.setStorageSync('historyGoodsPacking', Array.from(new Set(history_goodsPacking)).slice(0, 10).join(','))
      Taro.showToast({
        icon: "none",
        title: "修改成功",
      });
      sendGoodsStore.changeList.ssoId = resData.data.data.orderId || ''
      Taro.redirectTo({
        url: "/pages/changeOrder/success",
      });
    } else {
      Taro.showToast({
        icon: "none",
        title: "修改失败",
      });
    }
  });
  //   $get("/selfmachine-system/editOrder/getExplain", "").then((res: any) => {
  //     console.log(res, "字典");

  //   });

  //   Object.keys(req.body).forEach((key)=>{
  //     if(user[key] && user[key]!=req.body[key]){
  //         user[key] = req.body[key];
  //     }
  // })

  //   const result = await orderOrder(params);
  //   console.log(result);
  //   if (result.isSuccess == "1") {
  //     sendGoodsStore.success.orderId = result.orderId;
  //     sendGoodsStore.success.sendCode = result.sendCode;
  //     Taro.navigateTo({
  //       url: "/pages/sendGoods/success",
  //     });

  // -----------------------------------
  // Taro.showToast({
  //   icon: "success",
  //   title: "下单成功",
  // });
  //reset();
  // window.location.href = ''
  // window.scrollTo({
  //   top: 0,
  //   behavior: "smooth",
  // });
  // console.log(sendGoodsStore.goodsInfo,'打印查看一下');
  // goodsInfo.value = sendGoodsStore.goodsInfo;
}


async function getDesDistance(type) {// /selfmachine-system/branch/navigationRoute
  if (type == '1') {
    const res: any = await $post('/selfmachine-system/branch/queryDistance', [{
      branchCompanyNo: sendGoodsStore.sendBranch.info.branchno,
      originRegion: sendGoodsStore.sendAddressInfo ? sendGoodsStore.sendAddressInfo.preAddress : sendGoodsStore.changeList.toFromAdd,
    }])
    if (res.data.data && res.data.data.length) {
      return res.data.data[0].baiduDistance
    }
    else {
      return 0
    }
  }
  else {
    const res: any = await $post('/selfmachine-system/branch/queryDistance', [{
      branchCompanyNo: sendGoodsStore.getBranch.info.branchno,
      originRegion: sendGoodsStore.getAddressInfo ? sendGoodsStore.getAddressInfo.preAddress : sendGoodsStore.changeList.fromAdd,
    }])
    if (res.data.data && res.data.data.length) {
      return res.data.data[0].baiduDistance
    }
    else {
      return 0
    }
  }
}

const getAddressByLngLat = async (lng, lat) => {
  const res: any = await $get('/selfmachine-system/addressBook/reverseGeocoding', { longitude: lng, latitude: lat })
  return res.data.data
}
</script>

<style lang="scss">
.showc:after {
  display: none;
}

.insureMoney_active {
  /* 主蓝 */
  background: #0966ff !important;
}

.keep_money_foot {
  width: 100%;
  height: 128rpx;
  // background-color: red;
  position: fixed;
  bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 24rpx;
  box-sizing: border-box;
  justify-content: space-between;

  .left {
    display: flex;

    .one {
      font-family: PingFang SC Medium;
      font-size: 28rpx;
      color: #252525;
      font-weight: 700;
      margin-right: 16rpx;
    }

    .tow {
      font-family: PingFang SC Medium;
      font-size: 28rpx;
      color: #0966ff;
    }
  }

  .right {
    width: 460rpx;
    height: 88rpx;
    border-radius: 200rpx;
    background: #999999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: PingFang SC Medium;
    font-size: 32rpx;
    color: #ffffff;
  }
}

.clearingform {
  width: 100%;
  background-color: white;
  display: flex;
  justify-content: center;
  border-bottom: 1rpx solid #eee;

  .clearingform_div {
    margin-bottom: 22rpx;
    width: 654rpx;
    padding: 0 24rpx;
    box-sizing: border-box;
    border-radius: 8rpx;
    opacity: 1;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;

    .box {
      width: 100%;
      height: 88rpx;
      line-height: 88rpx;
      box-sizing: border-box;
      font-size: 28rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1rpx solid #e9e9e9;

      .box_label {
        width: 120rpx;
        color: #666666;
      }

      .box_value {
        width: calc(100% - 140px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: right;
        color: #252525;
      }

      &:last-child {
        border-bottom: none;
      }
    }
  }
}

.biaoji .biaoshi::after {
  display: none;
}

.biaoshi {
  padding-right: 25rpx !important;
}

.goods_infos {
  background-color: white;
  width: 100%;

  .goods_infos_div {
    width: 654rpx;
    height: 88rpx;
    background-color: #f5f5f5;
    margin-left: 24rpx;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .text {
      font-family: PingFang SC;
      font-size: 28rpx;

      /* 文字1 */
      color: #252525;
      margin-left: 25rpx;
      font-weight: 700;
      width: 440rpx;
      white-space: nowrap;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .edit {
      display: flex;
      align-items: center;
      font-family: PingFangSC-Regular;
      font-size: 24rpx;
      margin-right: 25rpx;

      .b {
        color: #0966ff;
      }

      .d {
        color: #fa5151;
        margin-left: 32rpx;
      }
    }

    &:first-child {
      border-radius: 8rpx 8rpx 0 0;
    }

    &:last-child {
      border-radius: 0 0 8rpx 8rpx;

      &:after {
        display: none;
      }
    }
  }

  .goods_infos_div:after {
    position: absolute;
    top: 0;
    left: 25rpx;
    box-sizing: border-box;
    width: 1208rpx;
    height: 200%;
    // border-right: 1px solid rgba(0, 0, 0, .1);
    border-bottom: 1rpx solid #c4c4c4;
    border-radius: inherit;
    content: " ";
    transform: scale(0.5);
    transform-origin: 0 0;
    pointer-events: none;
  }
}

.icon {
  vertical-align: middle;
}

.contain_sendgoods {
  height: 100vh;
  overflow: auto;
  box-sizing: border-box;
  font-size: 28rpx;
  background-color: #efeff4;
  padding-top: 14px;
  // padding: 16rpx 24rpx;
  // height: 1000rpx;
  // overflow: auto;

  .label {
    font-weight: 700;
    color: #000;
  }

  .goods_info {
    font-size: 32px;
    font-weight: 700;
    margin: 30px 0 30px 32px;
  }

  .sh-white-color {
    color: #fff;
  }

  .sh-text-666 {
    color: #666;
  }

  .sh-text-999 {
    color: #999;
  }

  .sh-text-25 {
    color: #252525;
  }

  // .sh-text-blue {
  //     color: #0966FF !important;
  // }

  .site-left {
    position: relative;

    .border-dash {
      position: absolute;
      top: 60px;
      left: 40px;
      height: 100px;
      border-left: 2px dashed #ccc;
    }
  }

  .site-right {
    color: #252525;

    .sh-write-color {
      color: #c4c4c4;
    }

    .sh-gary-color {
      color: #666;
    }
  }

  .cu-address {
    box-sizing: border-box;
    background-color: white;
    padding: 28px 28px;

    .sh-white-color {
      color: #fff;
    }

    .site-left {
      position: relative;

      .border-dash {
        position: absolute;
        top: 60px;
        left: 40px;
        height: 100px;
        border-left: 2px dashed #ccc;
      }
    }

    .site-right {
      color: #252525;

      .sh-write-color {
        color: #c4c4c4;
      }

      .sh-gary-color {
        color: #666;
      }
    }
  }

  .cu-get {
    display: flex;
    padding-right: 10px;
    height: 140px;
    background-color: #ffffff;
    justify-content: flex-end;
    align-items: center;
    // border-bottom: none !important;
  }

  // .cu-list.menu > .cu-item:nth-child(4):after {
  //   border-bottom: none;
  // }
  .button {
    box-sizing: border-box;
    padding: 30px 20px 0 20px;
  }

  .get-type {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 20px 20px;
    background-color: #f5f5f5;
    border-radius: 10px;
    margin-bottom: 40px;

    .leftImg {
      width: 112rpx;
      height: 112rpx;
      border-radius: 10rpx;
      background: url(../../assets/images/sendAddress/woyaofahuo_img_zitiwangdian@2x.png) no-repeat center;
      background-size: contain;
    }

    .info {
      padding: 0 0 0 16px;
      font-size: 22rpx;
      flex: 1;
      display: flex;
      flex-direction: column;
      // line-height: 32px;
      // height: 120px;
      background-color: ccc;

      .branch {
        // line-height: 56px;
        // line-height: 12px;
        font-size: 28rpx;
        font-weight: 700;
        margin-bottom: 6px;
      }

      .address {
        line-height: 28px;
        font-size: 22px;
        margin-bottom: 4px;
      }

      .tel {
        font-size: 22px;
      }

      // margin: 0 10rpx;
    }

    .rightImg {
      width: 48px;
      height: 48px;
      background: url("../../assets/images/sendAddress/woyaofahuo_icon_dianhua@2x.png") no-repeat center;
      background-size: contain;
    }
  }

  .get-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 20px;
    justify-content: space-between;
    background-color: #f5f5f5;
    height: 72px;
    border-radius: 10px;
    margin-bottom: 40px;
  }

  .goodsInfo {
    box-sizing: border-box;

    .nut-input .input-text {
      height: 68px;
      background-color: #f5f5f5;
      padding-left: 20px;
      line-height: 68px !important;
    }

    .nut-form-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .nut-input-number__text--input {
      width: 100px !important;
      height: 64px !important;
      border-top: 1px solid #c4c4c4 !important;
      border-bottom: 1px solid #c4c4c4 !important;
      background-color: #fff;
    }

    .goods-form {
      .nut-icon:before {
        width: 60px;
        height: 60px;
        line-height: 60px;
        text-align: center;
        background-color: #f8f9fa;
        border: 1px solid #c4c4c4;
      }
    }

    .nut-form-item__body__slots {
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }

  .keep_money {
    .money-height {
      position: relative;
      height: 450px;

      .pay_Info {
        // height: 200px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        background: #e5efff;
        font-size: 24px;
        margin: 10px 20px;
        padding: 24px;
        // span {
        //     font-size: 32rpx;
        // }
      }

      .keep_input {
        display: flex;
        align-items: center;
        // justify-content: space-between;
        padding: 0 20rpx;
        margin-bottom: 30px;
        // height: 100rpx;
        // line-height: 100rpx;

        .nut-input {
          flex: 1;
          height: 80px;
          margin: 0 40px;
          background-color: #f5f5f5;
        }
      }
    }

    // box-sizing: border-box;
    // margin-bottom: 140px;
    // padding-bottom: 140px;
  }

  .address_box {
    width: 100%;
    font-size: 24rpx;
    background-color: #fff;
    box-sizing: border-box;
    border-radius: 10rpx;
    margin-bottom: 20rpx;

    .address {
      display: flex;
      justify-content: flex-start;

      .info {
        max-height: 170px;
        // height: 150rpx;
        // width: 600rpx;
        margin-left: 80rpx;
        // line-height: 48rpx;
        padding: 32rpx 24rpx 0 0;
        // background-color: red;
      }

      .addressList {
        width: 116rpx;
        background-color: #fff;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border-radius: 10rpx;
      }

      a {
        font-size: 24rpx;
        color: blue;
      }
    }

    .name {
      display: flex;
      font-size: 32rpx;
      font-weight: 700;
    }

    .default {
      height: 80rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 32rpx;

      .set {
        display: flex;
      }
    }
  }

  .border {
    border-bottom: 1px solid #efeff4;
  }

  .radioType {
    width: 700rpx;
    background-color: #fff;
    border-radius: 20px;
    padding: 0 24px 24px 24px;
    box-sizing: border-box;
    margin-bottom: 20rpx;

    .item {
      display: flex;
      align-items: center;
      min-height: 100rpx;
      justify-content: space-between;
      border-bottom: 1px solid #ccc;
    }

    .item:nth-child(4) {
      border-bottom: none;
      margin-bottom: 0;
    }

    .item:nth-child(5) {
      border-bottom: none;
    }

    .point {
      height: 160rpx;
      display: flex;
      justify-content: flex-start;
      background-color: #f5f5f5;
      // align-items: center;
      margin-bottom: 10rpx;
      box-sizing: border-box;
      padding: 24rpx;

      .leftImg {
        width: 112rpx;
        height: 112rpx;
        border-radius: 10rpx;
        background: url(../../assets/images/sendAddress/woyaofahuo_img_zitiwangdian@2x.png) no-repeat center;
        background-size: contain;
      }

      .info {
        margin: 28px 0 0 16px;
        line-height: 22px;
        font-size: 22rpx;

        flex: 1;
        background-color: red;

        .branch {
          font-size: 28rpx;
          line-height: 32px;
          font-weight: 700;
        }

        .address {
          line-height: 12px;
        }
      }

      .rightImg {
        width: 48rpx;
        height: 48rpx;
        border-radius: 50%;
        // background: url(../../assets/images/sendAddress/woyaofahuo_icon_dianhua@2x.png) no-repeat center;
        background-size: contain;
      }
    }

    .alert {
      width: 20rpx;
    }
  }

  .more {
    width: 700rpx;
    background-color: #fff;
    border-radius: 20px;
    padding: 0 24rpx;
    box-sizing: border-box;
    margin-bottom: 20rpx;

    .item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 100rpx;
    }
  }

  .moreServer {
    width: 700rpx;
    background-color: #fff;
    border-radius: 10rpx;
    padding: 0 24rpx;
    box-sizing: border-box;
    margin-bottom: 20rpx;
    font-size: 28rpx;

    &>view {
      display: flex;
      align-items: center;
      height: 100rpx;
    }

    .item {
      justify-content: space-between;
    }
  }

  .message {
    .nut-checkbox__label {
      color: #999;
      margin-left: 10px;
    }

    display: flex;
    align-items: center;
    font-size: 16px;
    padding: 20px;
    color: #999;
    margin-bottom: 128rpx;

    label {
      color: #0966ff;
    }
  }
}

.foot {
  width: 100%;
  height: 128rpx;
  position: fixed;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  background: white;
}

.footer {
  position: fixed;
  bottom: 40rpx;
  width: 80%;
  height: 80rpx;
  left: 10%;
  border-radius: 40rpx;
  background-color: blue;
  color: #fff;
  text-align: center;
  line-height: 80rpx;
}

.custom-content {
  height: 400rpx;
  padding: 20rpx;
  font-size: 28rpx;
  color: #666;
}

.tips {
  color: #999999;
  font-size: 28rpx;
}

.receiveDate {
  font-size: 24rpx;

  .title {
    font-weight: 700;
    text-align: center;
    padding: 40rpx 0;
    border-bottom: 1px solid #ccc;
  }
}

.getGoods {
  box-sizing: border-box;

  // padding-bottom: 140px;
  .title {
    padding: 20rpx 0;
    font-size: 32rpx;
    line-height: 40rpx;
    font-weight: 700;
  }

  .protocol-list {
    box-sizing: border-box;
    background-color: #f5f5f5;
    overflow: auto;
    padding: 0 30px 30px;
    max-height: calc(100% - 260px);
  }

  .serve-list {
    box-sizing: border-box;
    background-color: #f5f5f5;
    // min-height: 450px;
    max-height: calc(100% - 260px);

    .item-height {
      min-height: 54px;
    }

    .card-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .ipt-box {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 52px;
      padding: 36px 20px;
      margin-top: 14px;
      border-radius: 10px;
      font-size: 26px;
      box-sizing: border-box;
      background-color: #f5f5f5;

      .ipt-box-title {
        width: 40%;
      }

      input {
        text-align: right;
      }

      .nut-radio-group {
        display: flex;
        align-items: center;
        font-size: 28px;

        .nut-radio {
          margin: 0;
          // margin-right: 8px;
        }
      }
    }

    .explain {
      margin-top: 14px;
      box-sizing: border-box;
      padding: 0 20px 16px;
      background: #e5efff;
      border-radius: 10px;
      border: 1px solid #b2d0ff;

      .explain-item {
        margin-top: 16px;

        .explain-title {
          font-size: 24px;
          color: #666666;
        }

        .explain-content {
          display: flex;
          flex-direction: column;
          font-size: 20px;
          color: #999999;
        }
      }
    }

    .agent-img {
      width: 38px;
      height: 38px;
      margin-right: 8px;
      background: url("../../assets/images/index/我要发货/woyaofahuo_icon_daishoufuwu@2x.png") no-repeat;
      background-size: contain;
    }

    .sign-img {
      width: 38px;
      height: 38px;
      margin-right: 8px;
      background: url("../../assets/images/index/我要发货/woyaofahuo_icon_qianshoudan@2x.png") no-repeat;
      background-size: contain;
    }
  }

  .list {
    box-sizing: border-box;
    max-height: 600px;
    overflow: auto;
    padding: 14px 24px 0 20px;
    background-color: #f5f5f5;

    .point {
      box-sizing: border-box;
      // height: 160rpx;
      display: flex;
      justify-content: flex-start;
      background-color: #fff;
      // align-items: center;
      margin-bottom: 14px;
      padding: 20px 24rpx;
      border-radius: 20px;

      .leftImg {
        width: 112rpx;
        height: 112rpx;
        border-radius: 10rpx;
      }

      .popular {
        background: url(../../assets/images/sendAddress/woyaofahuo_icon_推荐网点@2x.png) no-repeat center;
        background-size: contain;
      }

      .common {
        background: url(../../assets/images/sendAddress/woyaofahuo_img_wangdian@2x.png) no-repeat center;
        background-size: contain;
      }

      .rightImg {
        width: 36rpx;
        height: 36rpx;
        border-radius: 50%;
        border: 1px solid #c4c4c4;
      }

      .active {
        background: url(../../assets/images/sendAddress/icon_已选@2x.png) no-repeat center;
        background-size: contain;
      }
    }
  }

  .info {
    padding: 0 0 0 16px;
    font-size: 22rpx;
    flex: 1;
    display: flex;
    flex-direction: column;
    // line-height: 32px;
    // height: 120px;
    background-color: ccc;

    .branch {
      // line-height: 56px;
      // line-height: 12px;
      font-size: 28rpx;
      font-weight: 700;
      margin-bottom: 6px;
    }

    .address {
      line-height: 28px;
      font-size: 22px;
      margin-bottom: 4px;
    }

    .tel {
      font-size: 22px;
    }

    // margin: 0 10rpx;
  }
}

.leftButton {
  width: 128rpx;
  height: 48rpx;
  border-radius: 28rpx;
  background: #0966ff;
  font-family: PingFang SC;
  font-size: 24rpx;
  font-weight: normal;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 50rpx;
}

.biaoji {
  opacity: 1;
}

.biaoji>.arrow:before {
  display: none !important;
}

.comGoods {
  margin-right: 35rpx;
}

.h_item {
  width: 702rpx;
  background-color: white;
  display: flex;
  align-content: center;
  justify-content: center;
  flex-direction: column;
  //margin-left: 24rpx;
}
</style>
